package com.kaishengit.util;

import java.util.ArrayList;
import java.util.List;

import com.kaishengit.pojo.Linkman;
import com.kaishengit.pojo.Linkrecord;
import com.kaishengit.pojo.Trend;
import com.kaishengit.pojo.User;
import com.kaishnegit.entity.LinkmanEn;
import com.kaishnegit.entity.News;
import com.kaishnegit.entity.Record;

public class PTE {
	public static LinkmanEn LinkmanToLinkmanEn(Linkman linkman) {
		LinkmanEn len = new LinkmanEn();

		len.setId(linkman.getId());
		len.setName(linkman.getName());
		len.setCompany(linkman.getCompany());
		len.setMobile(linkman.getMobile());
		len.setPhone(linkman.getPhone());
		len.setEmail(linkman.getEmail());
		len.setAddress(linkman.getAddress());
		len.setHomepage(linkman.getHomepage());
		len.setTwtter(linkman.getTwtter());
		len.setDescr(linkman.getDescr());

		List<Record> records = new ArrayList<Record>();
		int n = 0;
		for (Linkrecord lin : linkman.getLinkrecords()) {

			records.add(LinkrecordToRecord(lin));
			n++;
			if (n > 2) {
				break;
			}
		}
		len.setRecords(records);
		return len;
	}

	public static Record LinkrecordToRecord(Linkrecord linkrecord) {
		Record record = new Record();
		record.setId(linkrecord.getId());
		record.setContent(linkrecord.getContent());
		record.setDate(linkrecord.getDate());
		record.setUsername(linkrecord.getUser().getUsername());
		return record;
	}

	public static News TrendToNews(Trend trend) {
		News news = new News();
		news.setId(trend.getId());
		news.setContent(trend.getContent());
		news.setDate(trend.getDate());
		//news.setUseren(UserToUseren(trend.getUser()))
		//news.setUser(UserToUseren(trend.getUser()));
		return news;
	}

	public static User UserToUseren(User user) {
		User useren = new User();
		useren.setId(user.getId());
		useren.setUsername(user.getUsername());
		return useren;
	}

}
